package com.echo.util;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

/**
 * Created by EchoGe on 2016/6/2.
 */
public class ActiveAndroidStrategy  implements ExclusionStrategy {

    private Class<?> excludedThisClass;
    private Class<?> excludedThisClassFields;

    public ActiveAndroidStrategy(Class<?> excludedThisClass, Class<?> excludedThisClassFields){
        this.excludedThisClass = excludedThisClass;
        this.excludedThisClassFields = excludedThisClassFields;
    }

    @Override
    public boolean shouldSkipField(FieldAttributes f) {
        return f.getDeclaringClass().equals(excludedThisClassFields);
    }

    @Override
    public boolean shouldSkipClass(Class<?> clazz) {
        if(clazz == null){
            return  false;
        }

        if(clazz.equals(excludedThisClass)){
            return true;
        }
        return shouldSkipClass(clazz.getSuperclass());
    }


}
